<!DOCTYPE html>
<html class="x-admin-sm">

<head>
   {include file='common/head' /}
</head>

<body>
<div class="x-nav">
            <span class="layui-breadcrumb">
                <a href="">首页</a>
                <a href="">系统管理</a>
                <a>
                    <cite>菜单管理</cite></a>
            </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" onclick="location.reload()" title="刷新">
        <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i>
    </a>
</div>
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-header">
                    <button onclick="xadmin.open('添加栏目','{:url('menu/add')}',500,500)" class="layui-btn" lay-filter="sreach"><i class="layui-icon"></i>增加栏目</button>
                </div>
                <div class="layui-card-body ">
                    <table class="layui-table layui-form">
                        <thead>
                        <tr>
                            <th width="70">ID</th>
                            <th width="120">栏目名</th>
                            <th width="120">栏目标识</th>
                            <th width="120">栏目描述</th>
                            <th width="80">状态</th>
                            <th width="80">排序</th>
                            <th width="250">操作</th>
                        </thead>
                        <tbody class="x-cate">
                        {volist name="lists" id="vo"}
                        <tr cate-id='{$vo.id}' fid='{$vo.pid}'>
                            <td>{$vo.id}</td>
                            <td>
                                {if $vo.pid == 0}
                                <i class="layui-icon x-show" status='true'>&#xe623;</i>{$vo.name}
                                {else /}
                                &nbsp;&nbsp;&nbsp;&nbsp;
                                ├{$vo.name}
                                {/if}
                            </td>
                            <td>{$vo.url}</td>
                            <td>{$vo.remark}</td>
                            <td>
                                {if $vo['status']==1}
                                <span class="layui-btn layui-btn-normal layui-btn-mini">已启用</span>
                                {else/}
                                <span class="layui-btn layui-btn-normal layui-btn-mini layui-btn-disabled">已禁用</span>
                                {/if}
                            </td>
                            <td>{$vo.sort}</td>
                            <td class="td-manage">
                                {if $vo['status']==1}
                                <a href="{:url('menu/change_status',['id'=>$vo['id'],'status'=>0,'name'=>$vo['name']])}" title="禁用" msg="确定要禁用此菜单吗?" class="ajax_get confirm"><i class="layui-icon">&#xe601;</i></a>
                                {else/}
                                <a href="{:url('menu/change_status',['id'=>$vo['id'],'status'=>1,'name'=>$vo['name']])}" title="启用" msg="确定要启用此菜单吗?" class="ajax_get confirm"><i class="layui-icon">&#xe62f;</i></a>
                                {/if}
                                <a href="javascript:;" title="编辑" onclick="xadmin.open('编辑','{:url('menu/edit',['id'=>$vo['id']])}',500,500)"><i class="layui-icon">&#xe642;</i></a>
                                <a href="{:url('del',['id'=>$vo['id'],'name'=>$vo['name']])}" title="删除" msg="确定要删除吗?" class="ajax_get confirm"><i class="layui-icon">&#xe640;</i></a>
                            </td>
                        </tr>
                        {/volist}
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>
<script src="__STATIC__/js/jquery-2.1.4.min.js"></script>
<script src="__STATIC__/js/common.js"></script>
<script>

    // 分类展开收起的分类的逻辑
    $(function(){
        $("tbody.x-cate tr[fid!='0']").hide();
        // 栏目多级显示效果
        $('.x-show').click(function () {
            if($(this).attr('status')=='true'){
                $(this).html('&#xe625;');
                $(this).attr('status','false');
                cateId = $(this).parents('tr').attr('cate-id');
                $("tbody tr[fid="+cateId+"]").show();
            }else{
                cateIds = [];
                $(this).html('&#xe623;');
                $(this).attr('status','true');
                cateId = $(this).parents('tr').attr('cate-id');
                getCateId(cateId);
                for (var i in cateIds) {
                    $("tbody tr[cate-id="+cateIds[i]+"]").hide().find('.x-show').html('&#xe623;').attr('status','true');
                }
            }
        })
    })

    var cateIds = [];
    function getCateId(cateId) {
        $("tbody tr[fid="+cateId+"]").each(function(index, el) {
            id = $(el).attr('cate-id');
            cateIds.push(id);
            getCateId(id);
        });
    }
    


</script>
</body>
</html>
